home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Best of www.BestZips.com (Collector's Edition)
/
Best of WWW.BESTZIPS.COM Collector's Edition (JCSM Shareware) (JCS Marketing).ISO
/
prgtools
/
euphor14.zip
/
CALLMACH.EX
< prev
next >
Wrap
Text File
|
1996-03-10
|
2KB
|
69 lines
-- Example of calling a machine code
-- routine from Euphoria
include machine.e
include graphics.e
sequence vc
vc = video_config()
atom screen
if vc[VC_COLOR] then
screen = #B8000 -- color
else
screen = #B0000 -- mono
end if
sequence string_copy_code, string
atom code_space, string_space, screen_location
clear_screen()
string = {'E', BRIGHT_BLUE, 'u', BRIGHT_GREEN, 'p', BRIGHT_CYAN,
'h', BRIGHT_RED, 'o', BRIGHT_MAGENTA, 'r', YELLOW,
'i', BRIGHT_WHITE, 'a', GREEN, '!', BROWN+128}
string_space = allocate(length(string)+1)
screen_location = screen + 11*80*2 + 64 -- 11 lines down
-- String Copy machine code:
-- (will move at least one char)
string_copy_code =
{#50, -- push eax
#53, -- push ebx
#52, -- push edx
#B8} & -- mov eax,
int_to_bytes(string_space) & -- string address (source)
{#BA} & -- mov edx,
int_to_bytes(screen_location) & -- screen address (destination)
{#8A, #18, -- L1: mov bl, [eax]
#40, -- inc eax
#88, #1A, -- mov [edx],bl
#83, #C2, #01, -- add edx, #1
#80, #38, #00, -- cmp byte ptr [eax], #00
#75, #F3, -- jne L1
#5A, -- pop edx
#5B, -- pop ebx
#58, -- pop eax
#C3} -- ret
-- poke in the machine code:
code_space = allocate(length(string_copy_code))
poke(code_space, string_copy_code)
-- poke in the string:
poke(string_space, string & 0)
puts(1, "\n calling machine code routine ... ")
-- call the machine code:
call(code_space) -- copies string to screen
-- these would be freed anyway when the program ends:
free(code_space)
free(string_space)
puts(1, "success\n")